package cn.stylefeng.guns.config;

import java.io.File;

import javax.servlet.MultipartConfigElement;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MultipartConfig {
	
	@Value("${zdcl.upload_tmp_path}")
	private String tmpPath;
	
	/**
     *文件临时上传路径
     */
   @Bean
   MultipartConfigElement multipartConfigElement() {
      MultipartConfigFactory factory = new MultipartConfigFactory();
      //String location  = System.getProperty("user.dir") +"/data/tmp";
     // String location  = "e:/tmp";
      File tmpFile   = new File (tmpPath);
      if(!tmpFile.exists()){
         tmpFile.mkdirs();
      }
      factory.setLocation(tmpPath);
      return factory.createMultipartConfig();
  }    

}
